package com.it.selfAfter.controller;

import java.text.SimpleDateFormat;

import com.it.selfAfter.dto.RegisterDTO;
import com.it.selfAfter.service.UserService;
import com.it.selfAfter.utils.Result;
import com.it.selfAfter.utils.UtilsRandomQuote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "*")// 解决跨域问题
@RequestMapping("/api/quote")
@Slf4j
@Api(tags = "用户相关接口,给用户提供每日名言")
public class QuoteController {

    @Autowired
    private UserService userService;

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @ApiOperation(value = "根据手机号更新每日名言", notes = "根据手机号更新每日名言")
    @PostMapping("/updateQuote")
    private Result<?> updateQuote(@ApiParam(value = "用户手机号", readOnly = true) @RequestBody RegisterDTO registerDTO){
//        String currentDate = dateFormat.format(new Date());
        String quote = UtilsRandomQuote.getQuote();
        String phone = registerDTO.getPhone();
        return userService.updateQuote(phone, quote);
    }
}